{% extends "top.html" %}

{% block title %}影视中心{% endblock %}

{% block css %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/movie.css') }}">
{% endblock %}

{% block page_title %}影视中心{% endblock %}

{% block content %}
<div class="movie-container">

    <!-- 资源菜单 -->
    <div class="resource-menu">
        {% for resource in resources %}
            <a href="/movie/?name={{ resource.name }}" class="resource-item 
            
            {% if resource.name == currentname %}active{% endif %}
            
            ">{{ resource.desc }}</a>
        {% endfor %}
    </div>

    <!-- 搜索栏 -->
    <div class="movie-search">
        <form action="/movie/search" method="GET">
            <input type="hidden" name="name" value="{{ currentname|default('', true) }}">
            <input type="text" name="wd" placeholder="输入影片名称..." value="{{ keyword|default('', true) }}">
            <button type="submit"><i class="fas fa-search"></i> 搜索</button>
        </form>
    </div>

    <!-- 分类导航 -->
    <div class="movie-nav">
        <div class="category-group">
            <h3>影片类型</h3>
            <div class="category-items">
                {% for category in categories %}
                    {% if category.type_pid == 0 %}
                    <a href="/movie/category/{{ category.type_id|int }}?name={{currentname}}" class="category-item {% if current_category == category.type_id|int %}active{% endif %}">
                        {{ category.type_name }}
                    </a>
                    {% endif %}
                {% endfor %}
            </div>
        </div>
        
        {% if subcategories %}
        <div class="category-group">
            <h3>{{ parent_category_name }}</h3>
            <div class="category-items">
                {% for category in subcategories %}
                <a href="/movie/category/{{ category.type_id|int }}?name={{currentname}}" class="category-item {% if current_category == category.type_id|int %}active{% endif %}">
                    {{ category.type_name }}
                </a>
                {% endfor %}
            </div>
        </div>
        {% endif %}
    </div>

    <!-- 影片列表 -->
    <div class="movie-list">
        <h2>{{ list_title|default('最新上线', true) }}</h2>
        
        {% if movies %}
        <div class="movie-grid">
            {% for movie in movies %}
            <div class="movie-item">
                <a href="/movie/detail/{{ movie.vod_id|int }}?name={{currentname}}">
                    <div class="movie-poster">
                        <img src="{{ movie.vod_pic|default(url_for('static', filename='images/error.png'), true) }}" 
                             alt="{{ movie.vod_name }}" 
                             onerror="">
                        <span class="movie-remarks">{{ movie.vod_remarks }}</span>
                    </div>
                    <div class="movie-info">
                        <h3 class="movie-title">{{ movie.vod_name }}</h3>
                        <p class="movie-meta">
                            <span class="movie-type">{{ movie.type_name }}</span>
                            <span class="movie-year">{{ movie.vod_time[:4] if movie.vod_time }}</span>
                        </p>
                    </div>
                </a>
            </div>
            {% endfor %}
        </div>
        
        <!-- 分页 -->
        {% if total_pages > 1 %}
        <div class="pagination">
            {% if current_page > 1 %}
            <a href="{{ pagination_url }}&pg={{ current_page - 1 }}" class="page-link">&laquo; 上一页</a>
            {% endif %}
            
            {% for i in range(1, total_pages + 1) %}
                {% if i >= current_page - 2 and i <= current_page + 2 %}
                <a href="{{ pagination_url }}&pg={{ i }}" class="page-link {% if i == current_page %}active{% endif %}">{{ i }}</a>
                {% endif %}
            {% endfor %}
            
            {% if current_page < total_pages %}
            <a href="{{ pagination_url }}&pg={{ current_page + 1 }}" class="page-link">下一页 &raquo;</a>
            {% endif %}
        </div>
        {% endif %}
        
        {% else %}
        <div class="no-results">
            <p>没有找到相关影片，请尝试其他关键词或分类</p>
        </div>
        {% endif %}
    </div>
</div>
{% endblock %} 